using System.Collections;
using UnityEngine;

namespace Character
{
    public class LeftPlayerCtrl : CharacterBase
    {
        private Transform _cardParent;

        private void Awake()
        {
            Bind(CharacterEvent.INIT_LEFT_CATD);
        }

        private void Start()
        {
            _cardParent = transform.Find("CardPoint");
        }

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case CharacterEvent.INIT_LEFT_CATD:
                {
                    StartCoroutine(InitCardList());
                    break;
                }
            }
        }

        private IEnumerator InitCardList()
        {
            var cardPrefab = Resources.Load<GameObject>("Card/OtherCard");

            for (var i = 0; i < 17; i++)
            {
                CreateGo(i, cardPrefab);
                yield return new WaitForSeconds(0.1f);
            }
        }

        /**
         * 创建卡牌
         */
        private void CreateGo(int index, GameObject cardPrefab)
        {
            var cardGo = Instantiate(cardPrefab, _cardParent);
            cardGo.transform.localPosition = new Vector2(0.15f * index, 0);
            cardGo.GetComponent<SpriteRenderer>().sortingOrder = index;
        }
    }
}